<?php
namespace app\admin\controller;

use support\Request;

class Admin_photo extends  Base
{
    protected $table = 'admin_photo';

    protected function initialize()
    {
        $this->model = new \app\admin\model\AdminPhoto;
    }

    public function index(Request $request)
    {
        if ($request->isAjax()) {
            $list = $this->model->order('id','desc')->paginate(['list_rows'=>$request->input('limit'),'page' => $request->input('page')]);
            $data = [
              'msg'   => '',
              'data'  => $list->items(),
              'code'  => 0,
              'count' => $list->total(),
              'limit' => $request->get('limit')
            ];
            return json($data);
        }
        return view('admin_photo/index');
    }

    public function add(Request $request)
    {
        return view('admin_photo/add');
    }

    public function del(Request $request)
    {
        return json(['code'=>201,'msg'=>'演示禁止删除']);
        $id = $request->input('id');
        try{
            $this->model->del($id);
        }catch (\Exception $e){
            return json(['code'=>201,'msg'=>'删除失败']);
        }
        return json(['code'=>200,'msg'=>'删除成功']);
    }

    public function del_all(Request $request)
    {
        return json(['code'=>201,'msg'=>'演示禁止删除']);
        $ids =  $request->input('ids');
        if (!is_array($ids)){
            return json(['code'=>201,'msg'=>'参数错误']);
        }
        try{
            foreach ($ids as $k) {
                $this->model->del($k);
            }
        }catch (\Exception $e){
            return json(['code'=>201,'msg'=>'删除失败']);
        }
        return json(['code'=>200,'msg'=>'删除成功']);
    }
}
